layui.use(['layer', 'table', 'jquery', 'form','laydate','upload'], function(){
    var $ = layui.jquery,
        layer = layui.layer,
        table = layui.table,
        laydate = layui.laydate,
        upload = layui.upload,
        form = layui.form;

    var $speInpContainers = $('.dynInputs .layui-col-xs6');
    //var urlProcessId = parent.$('#urlProcessId').val();
    var urlProcessId = params.urlProcessId



    //页面类型：0:新建 ； 1：编辑
    var pageType = params.pageType*1

    //设置页面名称
    var $pageTitle = $('.pageTitle');
    pageType == 0 ? $pageTitle.html('新增爬虫记录') : $pageTitle.html('编辑爬虫记录')*1;

    //重置按钮显隐
    pageType == 0 ? "" : $('.resetBtn').hide();

    $('.resetBtn').click(function () {
        $('input:hidden').val("");
    });
    if(pageType){
           var actionUrl = "../urlProcess/getUrlProcessDataMap";
           $.post(actionUrl,{urlProcessId:urlProcessId}, function (result) {
               if (result.code == 0) {
                   for(var key in result.data){
                       if($("#"+key)){
                           $("#"+key).val(result.data[key])
                       }
                   }
               } else {
                   layer.msg('请求失败', {icon: 2, time: 2000,shade: 0.1});
               }

           });
       }
       //表单提交
    form.on('submit(save)', function(data){
        var loadingIndex = layer.load(1, {time: 10*1000,shade: 0.1});
       // console.log(data.field); //当前容器的全部表单字段，名值对形式：{name: value}
        var actionUrl = "../urlProcess/urlProcessSave";
        $.post(actionUrl, data.field, function (result) {
            if (result.code == 0) {
                layer.msg('保存成功', {icon: 1, time: 1500,shade: 0.1}, function () {
                    if (result.data.id) {
                        $('#urlProcessId').val(result.data.id);
                        layer.close(loadingIndex);
                    }
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layui.table.reload("urlProcessList");
                    parent.layer.close(index);
                });
            } else {
                layer.msg('保存失败', {icon: 2, time: 2000,shade: 0.1});
            }

        });
        return false;
    });
});


